<?php
/**
 * KePHP, Keep PHP easy!
 */

namespace CSService\Controller;

use CSService\Helper\CSCipher;
use CSService\Model\Command\Command;
use CSService\Model\Project\Project;
use CSService\Model\Server\Server;
use CSService\Model\User\User;

class Index extends Abs
{

	public function index()
	{
		$this->servers = Server::find(['order' => 'position DESC']);
		$this->projects = Project::find();
		$this->commands = Command::find([
			'order' => [
				['group_id', 1],
				['position', 1],
			],
		]);
		$this->project = Project::findOne($this->http->query('p'));
	}

	public function login()
	{
		if ($this->user->isExists())
			return $this->redirect();
		$this->layout = 'login';
	}

	public function post_login()
	{
		$this->status = User::login($this->http);
		if ($this->status->isSuccess())
			return $this->redirect();
	}

	public function logout()
	{
		if ($this->user->isNew())
			return $this->redirect('login');
		User::logout();
		$this->redirect('login');
	}
}